/**
 *
 */
package co.fitstart.payment.alipay.pay;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @author lute
 *
 */
public class AlipayWapPayParameter {

    private String notifyURL;

    private String returnURL;

    private String body;

    private String subject;

    private String outTradeNo;

    private String timeoutExpress;

    private int totalAmount;

    private String sellerId;

    private String authToken;

    private String productCode;

    /**
     * @param notifyURL
     * @param returnURL
     * @param subject
     * @param outTradeNo
     * @param totalAmount
     * @param productCode
     */
    public AlipayWapPayParameter(String notifyURL, String returnURL, String subject, String outTradeNo, int totalAmount, String productCode) {
        this.notifyURL = notifyURL;
        this.returnURL = returnURL;
        this.subject = subject;
        this.outTradeNo = outTradeNo;
        this.totalAmount = totalAmount;
        this.productCode = productCode;
    }

    /**
     * @param body
     * @return
     */
    public AlipayWapPayParameter body(String body) {
        this.body = body;
        return this;
    }

    /**
     * @param timeoutExpress
     * @return
     */
    public AlipayWapPayParameter timeoutExpress(String timeoutExpress) {
        Pattern pattern = Pattern.compile("^(\\d+[mhd])|(1c)$");
        Matcher matcher = pattern.matcher(timeoutExpress);
        if (matcher.find()) {
            this.timeoutExpress = timeoutExpress;
        }
        return this;
    }

    /**
     * @param sellerId
     * @return
     */
    public AlipayWapPayParameter sellerId(String sellerId) {
        this.sellerId = sellerId;
        return this;
    }

    /**
     * @param authToken
     * @return
     */
    public AlipayWapPayParameter authToken(String authToken) {
        this.authToken = authToken;
        return this;
    }

    /**
     * @return  total amount string as RMB Yuan instead of cent.
     */
    public String getTotalAmountAsYuan() {
        BigDecimal total = new BigDecimal(this.totalAmount);
        BigDecimal hundred = new BigDecimal(100);
        return total.divide(hundred, 2, RoundingMode.DOWN).toString();
    }

    /**
     * @return the notifyURL
     */
    public String getNotifyURL() {
        return notifyURL;
    }

    /**
     * @return the returnURL
     */
    public String getReturnURL() {
        return returnURL;
    }

    /**
     * @return the body
     */
    public String getBody() {
        return body;
    }

    /**
     * @return the subject
     */
    public String getSubject() {
        return subject;
    }

    /**
     * @return the outTradeNo
     */
    public String getOutTradeNo() {
        return outTradeNo;
    }

    /**
     * @return the timeoutExpress
     */
    public String getTimeoutExpress() {
        return timeoutExpress;
    }

    /**
     * @return the totalAmount
     */
    public int getTotalAmount() {
        return totalAmount;
    }

    /**
     * @return the sellerId
     */
    public String getSellerId() {
        return sellerId;
    }

    /**
     * @return the authToken
     */
    public String getAuthToken() {
        return authToken;
    }

    /**
     * @return the productCode
     */
    public String getProductCode() {
        return productCode;
    }

}
